<?php

declare(strict_types=1);

namespace Api\Service\v1\Work;

use App\CustHub\Mapper\ChCorpMapper;
use App\CustHub\Service\OpenWorkService;
use App\CustHub\Work\TxlApiService;
use Hyperf\Di\Annotation\Inject;

class EmployeeApiService
{

    #[Inject]
    protected ChCorpMapper $corpMapper;

    /**
     * 获取部门列表
     * @param array $params
     * @return array|mixed
     */
    public function getDeptList(array $params): mixed
    {
        $service = make(OpenWorkService::class,[$params['corp_id']]);
        //获取部门列表
        $deptList = $service->getDepartmentList();
        return $deptList;
    }

    /**
     * 获取部门成员
     * @param array $params
     * @return array|mixed
     */
    public function getUserListByDeptId(array $params): mixed
    {
        $service = make(OpenWorkService::class,[$params['corp_id']]);
        //获取部门列表
        $deptList = $service->getUserListByDeptId($params['dept_id']);
        return $deptList;
    }

    public function getEmployees(array $params)
    {
        $corpInfo = $this->corpMapper->findById($params['corp_id']);

        $openWorkService = make(TxlApiService::class,[$corpInfo->auth_corp_id]);

        $openWorkService->getUserIdList();
    }


    public function syncEmployees(array $params)
    {
        $service = make(OpenWorkService::class,[$params['corp_id']]);

        //获取部门列表
        $deptList = $service->getDepartmentList();

        if($deptList){
            foreach ($deptList as $dept){
                $service->getUserList($dept['id']);
            }
        }

    }

    public function handleSyncData(OpenWorkService $service)
    {




    }
}